home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / Inside Mac Movie Toolbox Code / mtb4.c < prev    next >
Encoding:
Text File  |  1992-10-23  |  2.0 KB  |  89 lines  |  [TEXT/KAHL]

  1. //    Copyright:    © 1992 by Apple Computer, Inc., all rights reserved.
  2.  
  3. #include "mtb.h"
  4.  
  5. void main (void)
  6. {
  7.     WindowPtr                aWindow;
  8.     Rect                     windowRect;
  9.     Rect                     movieBox;
  10.     Movie                     aMovie;
  11.     Boolean                 done = false;        
  12.     OSErr                     err;
  13.     EventRecord theEvent;
  14.     WindowPtr                 whichWindow;
  15.     short                     part;
  16.  
  17.     InitGraf (&qd.thePort);
  18.     InitFonts ();
  19.     InitWindows ();
  20.     InitMenus ();
  21.     TEInit ();
  22.     InitDialogs (nil);
  23.  
  24.     if (!IsQuickTimeInstalled()) {
  25.         CheckError(-1,"\pPlease install QuickTime and try again.");
  26.         }
  27.     
  28.     err = EnterMovies ();
  29.     if (err) return;
  30.     
  31.     SetRect (&windowRect, 100, 100, 200, 200);
  32.     aWindow = NewCWindow (nil, &windowRect, "\pMovie",
  33.                                  false, noGrowDocProc, (WindowPtr)-1,
  34.                                  true, 0);
  35.  
  36.     SetPort (aWindow);
  37.     aMovie = GetMovie ();
  38.     if (aMovie == nil) return;
  39.     
  40.     GetMovieBox (aMovie, &movieBox);        
  41.     OffsetRect (&movieBox, -movieBox.left, -movieBox.top);
  42.     SetMovieBox (aMovie, &movieBox);
  43.     
  44.     SizeWindow (aWindow, movieBox.right, movieBox.bottom, true);
  45.     ShowWindow (aWindow);
  46.     
  47.     SetMovieGWorld (aMovie, (CGrafPtr)aWindow, nil);
  48.     
  49.     StartMovie (aMovie);
  50.     
  51.     while ( !IsMovieDone(aMovie) && !done ) {
  52.         if (WaitNextEvent (everyEvent, &theEvent, 0, nil)) {
  53.             switch ( theEvent.what ) {
  54.                 case updateEvt:    
  55.                     whichWindow = (WindowPtr)theEvent.message;
  56.                     if (whichWindow == aWindow) {
  57.                         BeginUpdate (whichWindow);
  58.                         UpdateMovie(aMovie);
  59.                         SetPort (whichWindow);
  60.                         EraseRect (&whichWindow->portRect);
  61.                         EndUpdate (whichWindow);
  62.                     }
  63.                     break;
  64.  
  65.                 case mouseDown:    
  66.                     part = FindWindow (theEvent.where,
  67.                                                  &whichWindow);
  68.                     if (whichWindow == aWindow) {
  69.                         switch (part) {
  70.                             case inGoAway:    
  71.                                 done = TrackGoAway (whichWindow,
  72.                                                              theEvent.where);
  73.                                 break;
  74.                             case inDrag:    
  75.                                 DragWindow (whichWindow,
  76.                                                  theEvent.where,
  77.                                                  &qd.screenBits.bounds);
  78.                                 break;
  79.                         }
  80.                     }
  81.                     break;
  82.             }
  83.         }
  84.         MoviesTask (aMovie, DoTheRightThing);
  85.     }
  86.     DisposeMovie (aMovie);
  87.     DisposeWindow (aWindow);
  88. }
  89.